package com.sicnu.startup.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sicnu.startup.entity.*;
import com.sicnu.startup.result.Result;
import com.sicnu.startup.service.*;
import com.sicnu.startup.vo.ProjectQueryVO;
import com.sicnu.startup.vo.ProjectVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zr
 * @since 2022-01-08
 */
@RestController
@RequestMapping("/startup/projects")
@CrossOrigin
public class ProjectsController {
    @Resource
    private ProjectsService projectsService;
    @Resource
    private NewsService newsService;
    @Resource
    private CitysService citysService;
    @Resource
    private RegionsService regionsService;
    @Resource
    private TypesService typesService;

    @PostMapping("add/project")
    public Result addProject(@RequestBody ProjectVO projectVO) {
        boolean flag = projectsService.saveProject(projectVO);
        return flag ? Result.ok() : Result.fail();
    }

    @GetMapping("list/project")
    public Result getProjectList() {
        List<Projects> projects = projectsService.getProjectList();
        List<News> newsList = newsService.getNews();
        Map<String, Object> map = new HashMap<>();
        map.put("projects", projects);
        map.put("newsList", newsList);
        return Result.ok(map);
    }

    @PostMapping("pageProjectCondition/{current}/{limit}")
    public Result getProjectCondition(@PathVariable long current,
                                      @PathVariable long limit,
                                      @RequestBody ProjectQueryVO projectQueryVO) {
        Page<Projects> projectsPage = new Page<>(current, limit);
        projectsService.getProjectCondition(projectsPage, projectQueryVO);
        return Result.ok(projectsPage);
    }

    @GetMapping("list/region")
    public Result getRegion() {
        List<Regions> list = regionsService.list(null);
        return Result.ok(list);
    }

    @GetMapping("list/type")
    public Result getType() {
        List<Types> list = typesService.list(null);
        return Result.ok(list);
    }

    @GetMapping("list/city")
    public Result getCities() {

        List<Citys> list = citysService.list(null);
        return Result.ok(list);
    }
}

